<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>2.1 数据操作</title>
</head>

<body>
  <script src="https://unpkg.com/san@latest/dist/san.dev.js"></script>

  <script>
    var MyApp = san.defineComponent({
      template:
        '<div>'
        + '<div class="text">'
        + '  <p><input type="text" value="{= name =}" placeholder="姓名" >'
        + '  <input type="number" value="{= age =}" placeholder="年龄">'
        + '  <input type="text" value="{= des =}" placeholder="简介"></p>'
        + ' <p><strong>信息</strong>：<button on-click="clear">移除信息</button></p>'
        + ' <p>姓名：<span>{{ name }}</span></p>'
        + ' <p>年龄：<span>{{ age }}</span></p>'
        + ' <p>简介：<span>{{ des }}</span></p>'
        + '</div> '
        + '</div>',

      initData: function () {
        return {
          name: '',
          age: undefined,
          des: ''
        };
      },
      clear: function () {
        this.data.set('name', '');
        this.data.set('age', undefined);
        this.data.set('des', '');
      }
    });
    var myApp = new MyApp();
    myApp.attach(document.body);
  </script>
  <style>
    .text {
      width: 580px;
      margin: 30px auto;
    }

    .text input {
      width: 160px;
      height: 30px;
      border: 1px solid #a1a1a1;
      text-indent: 10px;
    }

    .text span {
      display: inline-block;
      width: 100px;
      border-bottom: 1px solid #ccc;
      white-space: nowrap;
    }
  </style>
</body>

</html>